home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / Pedestal / Source / Sources / Streams / PedDataSourceFile.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  929 b   |  50 lines

  1. /*    ====================
  2.  *    PedDataSourceFile.cc
  3.  *    ====================
  4.  */
  5.  
  6. #include <Files.h>
  7.  
  8. #include <string.h>
  9.  
  10. #include "PedDataSourceFile.hh"
  11. #include "PedFSRef.hh"
  12. #include "PedBuffer.hh"
  13. #include "PedAccess.hh"
  14.  
  15.  
  16. PedDataSourceFile::PedDataSourceFile(PedFSRef &inFSRef, short inFork)
  17. {
  18.     PedAccessRaw *access = inFork
  19.         ? (PedAccessRaw *) new PedAccessRF(inFSRef, fsRdPerm)
  20.         : (PedAccessRaw *) new PedAccessData(inFSRef, fsRdPerm);
  21.     mAccess = access;
  22. }
  23.  
  24. PedDataSourceFile::~PedDataSourceFile()
  25. {
  26.     if (mAccess) {
  27.         mAccess->release();
  28.     }
  29. }
  30.  
  31. PedBuffer *
  32. PedDataSourceFile::GetNextBuffer()
  33. {
  34.     if (!mAccess) return NULL;
  35.     
  36.     enum {kDefaultBufferSize = 512};
  37.     long bytesRead;
  38.     PedBuffer *buf;
  39.     buf = new PedBuffer(kDefaultBufferSize);
  40.     bytesRead = mAccess->Read(kDefaultBufferSize, buf->Ptr());
  41.     if (bytesRead > 0) {
  42.         buf->SetLength(bytesRead);
  43.         buf->autorelease();
  44.         return buf;
  45.     } else {
  46.         delete buf;
  47.         return NULL;
  48.     }
  49. }
  50.